/****************************************************
* Unity版本：2022.1.21f1c1
* Version：0.1
* Company：DefaultCompany
* 日期：2023/09/14 18:08:03
*****************************************************/

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Car
{
    public int Passengers { get; set; }
}
public class DeliveryTruck
{
    public int GrossWeightClass { get; set; }
}

public class Taxi
{
    public int Fares { get; set; }
}

public class Bus
{
    public int Capacity { get; set; }
    public int Riders { get; set; }
}

public class PatternMatching : MonoBehaviour
{
    void Start()
    {
        //vehicle switch
        //{
        //    ...
        //    Car => 2.00m - 1.0m
        //}
    }

    public decimal CalculateToll(object vehicle) =>
    vehicle switch
    {
        Car { Passengers: 0 } => 2.00m + 0.50m,
        Car { Passengers: 1 } => 2.0m,
        Car { Passengers: 2 } => 2.0m - 0.50m,
        Car c => 2.00m - 1.0m,

        Taxi t => t.Fares switch
        {
            0 => 3.50m + 1.00m,
            1 => 3.50m,
            2 => 3.50m - 0.50m,
            _ => 3.50m - 1.00m
        },

        Bus b when ((double)b.Riders / (double)b.Capacity) < 0.50 => 5.00m + 2.00m,
        Bus b when ((double)b.Riders / (double)b.Capacity) > 0.90 => 5.00m - 1.00m,
        Bus b => 5.00m,

        DeliveryTruck t when (t.GrossWeightClass > 5000) => 10.00m + 5.00m,
        DeliveryTruck t when (t.GrossWeightClass < 3000) => 10.00m - 2.00m,
        DeliveryTruck _ => 10.00m,

        { } => throw new ArgumentException(message: "Not a known vehicle type", paramName: nameof(vehicle)),
        null => throw new ArgumentNullException(nameof(vehicle))
    };
}
